package com.hyq.learn.api.service;

import com.hyq.learn.api.model.request.ValidatedTwoRequest;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

/**
 * Validated 注解必须放在类上面，否则单方法参数校验不生效
 *
 * @author heyuqin
 * @date 2024/9/4 11:16
 */
@Service
@Validated
public class ValidatedService {

    private static final Logger LOGGER = LoggerFactory.getLogger(ValidatedService.class);

    public String test(@NotBlank String name, @NotNull Integer age) {
        LOGGER.info("service 参数校验通过");
        return "service 参数校验通过";
    }

    @NotNull
    public String test_2(@Valid ValidatedTwoRequest request) {
        LOGGER.info("service test_2 参数校验通过");
        return "service test_2 参数校验通过";
    }
}
